package com.share.demo.controller;

import com.share.demo.domain.User;
import com.share.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * caifan 2017/9/3
 */
@RestController
@RequestMapping("/rest/user")
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping(value = "/getUserById", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public ResponseEntity findUserById(@RequestParam Long id) {
        return new ResponseEntity(userService.findById(id), HttpStatus.OK);
    }

    @RequestMapping(value = "/insertUser", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public ResponseEntity insertUser(@RequestBody User user) {
        userService.insert(user);
        return new ResponseEntity(HttpStatus.OK);
    }
}
